package com.ruoyi.web.controller.xsp;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.xsp.domain.AdCarousel;
import com.ruoyi.xsp.service.IAdCarouselService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 广告管理Controller
 * 
 * @author zhiminhu
 * @date 2021-03-21
 */
@Controller
@RequestMapping("/xsp/carousel")
public class AdCarouselController extends BaseController
{
    private String prefix = "xsp/carousel";

    @Autowired
    private IAdCarouselService adCarouselService;

    @RequiresPermissions("xsp:carousel:view")
    @GetMapping()
    public String carousel()
    {
        return prefix + "/carousel";
    }

    /**
     * 查询广告管理列表
     */
    @RequiresPermissions("xsp:carousel:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AdCarousel adCarousel)
    {
        startPage();
        List<AdCarousel> list = adCarouselService.selectAdCarouselList(adCarousel);
        return getDataTable(list);
    }

    /**
     * 导出广告管理列表
     */
    @RequiresPermissions("xsp:carousel:export")
    @Log(title = "广告管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AdCarousel adCarousel)
    {
        List<AdCarousel> list = adCarouselService.selectAdCarouselList(adCarousel);
        ExcelUtil<AdCarousel> util = new ExcelUtil<AdCarousel>(AdCarousel.class);
        return util.exportExcel(list, "carousel");
    }

    /**
     * 新增广告管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存广告管理
     */
    @RequiresPermissions("xsp:carousel:add")
    @Log(title = "广告管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AdCarousel adCarousel)
    {
        return toAjax(adCarouselService.insertAdCarousel(adCarousel));
    }

    /**
     * 修改广告管理
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        AdCarousel adCarousel = adCarouselService.selectAdCarouselById(id);
        mmap.put("adCarousel", adCarousel);
        return prefix + "/edit";
    }

    /**
     * 修改保存广告管理
     */
    @RequiresPermissions("xsp:carousel:edit")
    @Log(title = "广告管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AdCarousel adCarousel)
    {
        return toAjax(adCarouselService.updateAdCarousel(adCarousel));
    }

    /**
     * 删除广告管理
     */
    @RequiresPermissions("xsp:carousel:remove")
    @Log(title = "广告管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(adCarouselService.deleteAdCarouselByIds(ids));
    }
}
